
<template>
  <el-dialog :title="title" :width="width" :visible.sync="isShowVisible" center :close-on-click-modal="false" :before-close="() => $emit('notRefresh')">
    <el-form label-width="125px" :model="materialData" ref="materialData" :rules="rules" style="min-height:24vw" v-loading="isLoading">
      <el-tabs>
       
          <el-card>
            <el-row>
                <el-col :span="12">
                <el-form-item label="订单编码:" prop="fnumber">
                  <el-input v-model="materialData.fnumber" disabled></el-input>
                </el-form-item>
              </el-col>
                <el-col :span="12">
                <el-form-item label="订单分录:" prop="fworkorderentrtyid">
                   <inputSelect v-if="!isLoading" :f7Disable="isview" v-model="materialData.fworkorderentrtyid" 
                   :loadShow="materialData.fmaterialname" 
                   :f7Param="materialf7Param" title="分录列表"
                    @onF7DaTaSelected="onF7MaterialSelected" >
                    </inputSelect>
                </el-form-item>
              </el-col>
              
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="产品编码" prop="fmaterialnumber">
                  <el-input v-model="materialData.fmaterialnumber" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="预计产量" prop="fqty">
                  <el-input v-model="materialData.fqty"  disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="产品批号:" prop="fmaterialflot">
                 <el-input v-model="materialData.fmaterialflot" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="产品型号" prop="fmaterialmodel">
                  <el-input v-model="materialData.fmaterialmodel" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
<el-row>
<el-col :span="12">
<el-form-item label="设备" prop="fmachineid" >
              <inputSelect 
              v-if="!isLoading"
              v-model="materialData.fmachineid" 
              :f7Param="machineF7Param" 
                    :loadShow="materialData.fmachinenumber" 
                    title="设备信息表"
                    :f7Disable="isview"
                     @onF7DaTaSelected="onF7MachineSelected"
                   ></inputSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设备名称" prop="fmachinename" >
                <el-input v-model="materialData.fmachinename" disabled></el-input>
            </el-form-item>
          </el-col>
          </el-row>
            
          <el-row>
          <el-col :span="12">
            <el-form-item label="模具" prop="fmodid" >
              <inputSelect 
              v-model="materialData.fmodid" 
              v-if="!isLoading"
              :f7Param="modF7Param" 
              :f7Disable="isview"
                    :loadShow="materialData.fmodnumber" 
                    title="模具信息表"
                     @onF7DaTaSelected="onF7ModSelected"
                   ></inputSelect>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="模穴数量" prop="fmodcavity" >
                <el-input v-model="materialData.fmodcavity" disabled></el-input>
            </el-form-item>
          </el-col>

</el-row>

            <el-row>
              <el-col :span="12">
                <el-form-item label="合格数量:" prop="fgoodqty">
                  <el-input v-model="materialData.fgoodqty" :disabled = "isview" type="number"></el-input>
                </el-form-item>
              </el-col>
             <el-col :span="12">
                <el-form-item label="不合格数量:" prop="fbadqty">
                  <el-input v-model="materialData.fbadqty" :disabled = "isview" type="number"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="操作员:" prop="fuserid" id="fuserid"
                 v-if="isshow">
              <inputSelect v-if="!isLoading" 
              v-model="materialData.fuserid"
               :loadShow="materialData.fusername"
                :f7Param="f7Param" 
                :f7Disable="isview"
                title="员工列表"></inputSelect>            
            </el-form-item>
              </el-col>
                <el-col :span="12">
                <el-form-item label="汇报时间:" prop="fbizdate">
                  <el-date-picker v-model="materialData.fbizdate" type="datetime" format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期" :disabled="isview">
                      </el-date-picker>
                </el-form-item>
              </el-col>
               
              </el-row>
              <el-row>
                
                <el-col :span="12">
                <el-form-item label="产品ID:" prop="fmaterialid" v-if="false">
                 <el-input v-model="materialData.fmaterialid"></el-input>
                </el-form-item>
              </el-col>
              </el-row>
          </el-card>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-if="!isview" type="primary" @click="saveMaterial">保存</el-button>
      <el-button v-if="!isview" @click="$emit('notRefresh')">取消</el-button>
      <el-button v-if="isview" @click="$emit('notRefresh')">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import xuReportApi from "@/api/xuSimpleWork/ReportApi"
export default {
  name: 'report_add',
  props: {
    width: { type: String, default: '80vw' },
    fid: { type: Number, },
    isview: false,
    operation: { type: String }
  },
  data () {
    return {
        isshow : false,
        fnumberAnable: true,
        title: '创建订单',
        isShowVisible: true,
        show:false,
        service  :new xuReportApi() ,
        materialf7Param : {
            selectId:'fid',
            selectUrl:'/tie-demo/xuWorkOrderEntry/queryXdEntryListPage',
            selectShow:{spt:'',field:['fmaterialname']},
            column:[
           
            {lable:'生产批号',prop:'flot',isFilter:true,filterField:'flot'},
            {lable:'产品',prop:'fmaterialid',isFilter:false,filterField:'fmaterialid'},
            {lable:'产品名称',prop:'fmaterialname',isFilter:false,filterField:'fmaterialname'},
            {lable:'产品简称',prop:'fsimplename',isFilter:false,filterField:'fsimplename'},
            {lable:'预计产量',prop:'fqty',isFilter:false,filterField:'fqty'},
            {lable:'产品类型',prop:'fmaterialmodel',isFilter:true,filterField:'fmaterialmodel'}
            ],
        },
      f7Param : {
        selectId:'userId',
        selectUrl:'/tie-system/entUser/queryListPage',
        selectTreeField:['companyId','deptId'],
        selectTreeUrl:'/tie-system/entUser/queryGroupTree',
        selectShow:{spt:'',field:['userName']},
        column:[{lable:'编号',prop:'userCode',
        isFilter:true,filterField:'userCode'},
        {lable:'名称',prop:'userName',isFilter:true,filterField:'name'}]
      },
    modF7Param :{
            selectId:'fid',
            selectUrl:'/tie-eqp/mould/queryListPage',
            selectTreeField:['fgroupid'],
            selectTreeUrl:'/tie-eqp/mouldgroup/queryGroupTree',
            selectShow:{spt:'',field:['fnumber']},
            column:[
              {lable:'编号',prop:'fnumber',isFilter:true,filterField:'fnumber'},
             
              {lable:'体积',prop:'fcavity',isFilter:true,filterField:'fcavity'},
            ],
            
        },
        machineF7Param :{
            selectId:'fid',
            selectUrl:'/tie-eqp/equipment/queryListPage',
            selectTreeField:['fgroupid'],
            selectTreeUrl:'/tie-eqp/equipmentGroup/queryGroupTree',
            selectShow:{spt:'',field:['fnumber']},
            column:[
              {lable:'编码',prop:'fnumber',isFilter:true,filterField:'fnumber'},
             
              {lable:'名称',prop:'fname',isFilter:false,filterField:'fname'}
            ,{lable:'规格型号',prop:'fmodel',isFilter:false,filterField:'fmodel'}
            ,{lable:'车间',prop:'fuseaddress',isFilter:true,filterField:'fuseaddress'}
            ],
        },
    rules:{
        fgoodqty: [{required:true,message:'请填写合格数量'}],
        fbadqty: [{required:true,message:'请填写不合格数量'}],
        fbizdate:[{required:true,message:'请选择汇报日期'}],
        fmachineid:[{required:true,message:'请选择设备'}],
        fmodid:[{required:true,message:'请选择模具'}],
        fuserid:[{required:true,message:'请选择操作员'}],
        fworkorderentrtyid:[{required:true,message:'请选择分录'}],

    },
      materialData: { },
      isLoading: true,
      materialData:{},
    }
  },
  
  async created () {
    this.isLoading = true
    await this.$NumRuleUtil.getNumber(this, "cn.hxlc.tie.demo.modular.jf.model.result.XjfReqMaterialResult", null, 'materialData', 'fnumberAnable', 'fnumber');
    if(this.operation == 'add'){
        }
        else{
          this.isshow = true;
    if(this.operation == 'edit'){
        this.title = "编辑汇报单"
          }else if(this.operation == 'view'){
              this.title = "查看汇报单";
              this.show= true
                this.rules = {};
          }
          let materialData = await this.service.detail({ fid: this.fid })
          this.materialData = materialData.data
      }
    this.isLoading = false
  },
  methods: {
onF7ModSelected(row){
        this.materialData.fmodcavity = row.fcavity;
      },
      onF7MachineSelected(row){
        this.materialData.fmachinename = row.fname;
      },

    onF7MaterialSelected(row){
      if(row!=null&&row!=''){
        this.materialData.fmaterialname = row.fmaterialname;
        this.materialData.fmaterialmodel = row.fmaterialmodel;
        this.materialData.fmaterialnumber = row.fmaterialnumber;
        this.materialData.fqty = row.fqty;
        this.materialData.fmaterialflot = row.flot;
        this.materialData.fmaterialid = row.fmaterialid
      }
      else{
         this.materialData.fmaterialname = ''
        this.materialData.fmaterialmodel = ''
        this.materialData.fmaterialnumber = ''
        this.materialData.fqty = ''
        this.materialData.fmaterialflot = ''
        this.materialData.fmaterialid = ''
      }
       
      },
    saveMaterial () {
        let materialData = this.materialData
      this.$refs['materialData'].validate((valid, object) => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: '请耐心等待.....',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })
          //若有fid证明是编辑没有则是新增
          if (this.fid) {
            materialData.fstatus = 1
            this.service.update(this.materialData).then(res => {
              loading.close()
              this.$tie.showSuccess(res.message)
              this.$emit('close')
            }).catch(e => {
              loading.close()
            })
          } else {
            materialData.fstatus = 0
            this.service.add(this.materialData).then(res => {
              loading.close()
              this.$tie.showSuccess(res.message)
              this.$emit('close')
            }).catch(e => {
              loading.close()
            })
          }
        }
        //  else {
        //   let validArr = []
        //   Object.keys(object).forEach(function (key) {
        //     validArr.push(key)
        //   });
        //   let validVal = "#" + validArr[0];
        //   document.querySelector(validVal).scrollIntoView(true);
        // }
      })
      
    },
  },
}
</script>

<style >
.vxe-select--panel {
  z-index: 3001 !important;
}

 .vxe-input--panel.type--date, .vxe-input--panel.type--month, .vxe-input--panel.type--            week, .vxe-input--panel.type--year {
  z-index: 9998 !important
    }

.col--actived{
  height: 100px !important;

  .vxe-cell{
    height: 100%;

    textarea{
      height: 100%;
    }
  }
}

</style>

